package com.example.system.controller;


import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.teacher.dto.TeacherQueryDTO;
import com.example.system.domain.teacher.dto.TeacherSaveDTO;
import com.example.system.domain.teacher.vo.TeacherDetailVO;
import com.example.system.domain.teacher.vo.TeacherSelectVO;
import com.example.system.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController extends BaseController {

    @Autowired
    private ITeacherService teacherService;

    // 教师注册接口
    // 教师账号由管理员进行注册
    // 所以教师管理页面需要有一个添加教师按钮

    @PostMapping("/add")
    public R<Void> add(@RequestBody TeacherSaveDTO teacherSaveDTO) {
        return toR(teacherService.add(teacherSaveDTO));
    }
    @DeleteMapping("/delete")
    public R<Void> delete(Long teacherId) {
        return toR(teacherService.delete(teacherId));
    }

    @GetMapping("/list")
    public TableDataInfo list(TeacherQueryDTO teacherQueryDTO){
        return getTableDataInfo(teacherService.list(teacherQueryDTO));
    }

    @GetMapping("/detail")
    public R<TeacherDetailVO> detail(Long teacherId) {
        return R.ok(teacherService.detail(teacherId));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody TeacherSaveDTO teacherEditDTO) {
        return toR(teacherService.edit(teacherEditDTO));
    }

    @GetMapping("/selectList")
    public R<List<TeacherSelectVO>> selectList(){
        List<TeacherSelectVO> teacherSelectVOS = teacherService.selectList();
        return R.ok(teacherSelectVOS);
    }
}
